package com.xj.controller;

import com.xj.sever.UserSever;
import com.xj.until.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@Api(value = "用户中心",tags = "用户中心接口")
@RestController
public class Personalcenter {

    @Autowired
    UserSever sever;

    @ApiOperation("用户信息")
    @PreAuthorize("hasAuthority('selectca')")
    @GetMapping("/center/select")
    public Result selectALl(){
        return sever.centSelect();
    }

    @ApiOperation("修改密码")
    @PostMapping("/center/updatepassword")
    public Result updatepassword(String password, String newpassword){
        return sever.updatePassword(password,newpassword);
    }
    @ApiOperation("修改邮箱发送验证码")
    @PostMapping("/center/usendemail")
    public Result usendemail(){
        return sever.updateemail();
    }

    @ApiOperation("接受修改验证码")
    @PostMapping("/center/updateemail")
    public Result updateemail(String code){
        return sever.emailcode(code);
    }

    @ApiOperation("修改邮箱")
    @PostMapping("/center/update1email")
    public Result update1email(String email){
        return sever.emali1(email);
    }

    @ApiOperation("修改手机号发送验证码")
    @PostMapping("/center/sendphone")
    public Result sendphone(){
        return sever.sendphone();
    }

    @ApiOperation("接受手机修改验证码")
    @PostMapping("/center/sendphone1")
    public Result sendphone1(String code){
        return sever.sendphone1(code);
    }

    @ApiOperation("接受手机修改验证码")
    @PostMapping("/center/phone")
    public Result phone(String phone){
        return sever.phone(phone);
    }








    @Autowired
    RocketMQTemplate rocketMQTemplate;
    @GetMapping("/sync")
    public void sync(){
        System.out.println();
        System.out.println("=======================同步发送=======================");
        String msg = "这是一条同步的消息";
        SendResult sendResult = rocketMQTemplate.syncSend("sync", msg);
        System.out.println("生产者:  同步消息发送成功："+sendResult);
        log.info("生产者:  同步消息发送成功：{}",sendResult);
    }





}
